////////
//  Watch Parameters : Example
////////
--[[
Watch Parameters is an extension that allows you to enable a watch on a parameter.



- PLUGIN:AddParameter(string ParameterName, table Data, (opt) bool ShouldWatch).
- PLUGIN:HasChanged(string ParameterName)
- PLUGIN:FlushParameter(string ParameterName)
- PLUGIN:FlushChanges()

  Pass true to the third argument on PLUGIN:AddParameter( ... ) to enable watch on this variable.
  Watch is only available when the plugin is mounted.
  
  
  
  When a Parameter changes while the plugin is running, it will be permanently set to a Changed state (true),
  and its state won't be monitored again until you flush the Parameter.
  
  You can query if a Parameter has changed using PLUGIN:HasChanged(string ParameterName) .
  This value persists during execution, so you can even call it in a non-think function.
  
  You can reset the Parameter "Changed" state using PLUGIN:FlushParameter(string ParameterName) .
  You can globally flush all Parameters states using PLUGIN:FlushChanges() .
  
  Watching and Flushing consumes neglictible CPU time, but it can easily get worse
  if you ever enable watch on ALL parameters for no reason. Only enable Watch Parameters
  when really needed.
  
  
  
  Watch is not available for Perform-type Plugins.
  Watch States are erased on unmount. It will not detect changes between two mounts.
  Watch States are especially Flushed automatically after PLUGIN:Load() .
]]--

PLUGIN.Name = "Stuff maker"
PLUGIN.DefaultOn = false
PLUGIN.Description = "Does stuff."
PLUGIN.Trigger = false


function PLUGIN:LoadParameters()
	self:AddParameter( "mycheckbox" , { Type = "checkbox", Text = "Status" }, true ) -- THIRD ARGUMENT : WATCH ENABLED.
	
	-- Enabling Watches on Labels or Buttons have NO Effect and does not even register into the check table internally.
	self:AddParameter( "btn_changed" , { Type = "button", Text = "Did it change ?", DoClick = self._DidItChange } )
	self:AddParameter( "btn_changed_and_reset" , { Type = "button", Text = "Did it change ? If yes, reset.", DoClick = self._DidItChangeReset } )
	self:AddParameter( "btn_flush" , { Type = "button", Text = "Flush Changes", DoClick = self._Flush } )
end

function PLUGIN:_DidItChange()
	chat.AddText( self:HasChanged("mycheckbox") and "Yes" or "No" )
end

function PLUGIN:_DidItChangeReset()
	chat.AddText( self:HasChanged("mycheckbox") and "Yes" or "No" )
	
	if self:HasChanged("mycheckbox") then
		self:FlushParameter("mycheckbox")
		chat.AddText( "Resetting parameter watch..." )
	end
end

function PLUGIN:_Flush()
	self:FlushChanges()
	chat.AddText( "Resetting ALL parameter watches..." )
end

